package com.example.administrator.zhongyichou.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.example.administrator.zhongyichou.Bean.DiseaseInfoBean;
import com.example.administrator.zhongyichou.Bean.SupplyDiseaseBean;
import com.example.administrator.zhongyichou.base.BaseActivity;
import com.example.administrator.zhongyichou.Bean.BaseEventBean;
import com.example.administrator.zhongyichou.config.Constants;
import com.example.administrator.zhongyichou.help.CallPhone;
import com.example.administrator.zhongyichou.net.core.HttpLoader;
import com.example.administrator.zhongyichou.net.protocol.GsonBaseProtocol;
import com.example.administrator.zhongyichou.view.HeaderView;
import com.example.administrator.zhongyichou.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lichenyu on 2017/11/21.
 * 描述：发起筹款成功
 */

public class InitiateFundraisingSuccessActivity extends BaseActivity {
    @BindView(R.id.headerview)
    HeaderView headerview;
    @BindView(R.id.btn_replenishment)
    Button btnReplenishment;
    @BindView(R.id.btn_view)
    Button btnView;
    @BindView(R.id.ll_call)
    LinearLayout llCall;
    private DiseaseInfoBean diseaseInfoBean;
    private int degreeDisease = 0;//补充资料的程度，0没有补充，1补充完第一步，2全部补充
    //// TODO: 2017/12/8  supply_id这个值是服务器补充资料的外键，因为补充资料2步做成相互独立的了，这个值就暂时没用了，留在这里没删
    private String supply_id;

    @Override
    protected void init() {
        ButterKnife.bind(this);
        initHead();
    }

    @Override
    protected void responseData(GsonBaseProtocol mGsonBaseProtocal) {

    }

    @Override
    protected HttpLoader initHttpLoader() {
        return null;
    }

    @Override
    protected int initContentView() {
        return R.layout.initiate_fundraising_success_activity;
    }

    @Override
    public boolean onEventBus(BaseEventBean baseEventBean) {
        //上个界面传来的参数
        if (baseEventBean.code == Constants.TYPE_0) {
            diseaseInfoBean = (DiseaseInfoBean) baseEventBean.data;
        }
        //补充资料第一个界面传回
        else if (baseEventBean.code == Constants.TYPE_1) {
            SupplyDiseaseBean bean = (SupplyDiseaseBean) baseEventBean.data;
            degreeDisease = bean.degree;
            supply_id = bean.supply_id;
        }
        //补充资料第二个界面传回，或者梦想筹款补充资料界面传回
        else if (baseEventBean.code == Constants.TYPE_2) {
            btnReplenishment.setVisibility(View.GONE);
        }
        return true;
    }

    @OnClick({R.id.btn_replenishment, R.id.btn_view, R.id.ll_call})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_replenishment://补充资料
                if (diseaseInfoBean.getType() == 0) {//大病
                    switch (degreeDisease) {
                        case 0:
                            Intent intent = new Intent(this, ReplenishmentDiseaseInformationActivity.class);
                            intent.putExtra("info_id", diseaseInfoBean.getInfoID());
                            startActivity(intent);
                            break;
                        case 1:
                            Intent intent1 = new Intent(this, ReplenishmentDiseaseInformationTwoActivity.class);
                            intent1.putExtra("info_id", diseaseInfoBean.getInfoID());
                            intent1.putExtra("supply_id", supply_id);
                            startActivity(intent1);
                            break;
                    }
                } else {//梦想
                    Intent intent = new Intent(this, DreamDataActivity.class);
                    intent.putExtra("info_id", diseaseInfoBean.getInfoID());
                    startActivity(intent);
                }
                break;
            case R.id.btn_view://查看项目
                if (diseaseInfoBean.getType() == 0) {//大病
                    Intent intent = new Intent(this, MyDiseaseDetailsActivity.class);
                    intent.putExtra("info_id", diseaseInfoBean.getInfoID());
                    startActivity(intent);
                } else {//梦想
                    Intent intent = new Intent(this, MyDreamDataActivity.class);
                    intent.putExtra("info_id", diseaseInfoBean.getInfoID());
                    startActivity(intent);
                }
                break;
            case R.id.ll_call://拨打电话
                CallPhone.call(this, R.string.phone + "");
                break;
        }
    }

    private void initHead() {
        headerview.setTitle("发起成功");
        headerview.bindOnclickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case HeaderView.LEFT:
                        finish();
                        break;
                }
            }
        });
    }
}
